<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>自定义promise</title>
  <script src="./promise.js"></script>
</head>
<body>
  <script>
    new Promise((resolve, reject) => {
      console.log('promise start');
      setTimeout(() => {
        resolve(666) 
      });
      console.log('1')
    })
    .then(
      value => {
        console.log('then1-resolve:', value)
        return new Promise((resolve, reject) => {
          resolve(9)
        })
      }, 
      reason => {
        console.log('then1-reject:', reason);
        throw 123
      }
    )
    .then(
      value => {
        console.log('then2-resolve:', value);
      }, 
      reason => {
        console.log('then2-reject:', reason);
      }
    )
    .catch(err => {
      console.log('err:', err)
    })

    let p = Promise.resolve(456)
    p.then(value => {
      console.log('promise-resolve:', value)
      throw 88
    }).catch(err => {
      console.log('catch:', err);
    })

    console.log('promise end')


    let p1 = Promise.resolve(1)
    let p2 = Promise.resolve(2)
    let p3 = Promise.reject(3)

    let pAll = Promise.all([p1, p2, p3])
    pAll.then((
      values => console.log(values)
    )).catch(err => {
      console.log(err);
    })
  </script>
</body>
</html>